/*   time:2019-06-13 20:39:24*/
var t = getApp(),
    e = t.requirejs("core"),
    a = t.requirejs("foxui");
Page({
    data: {
        list: [],
        indicatorDots: !1,
        autoplay: !1,
        current: 0,
        modal: !1
    },
    onLoad: function(a) {
        var e = this,
            i = {
                cate: a.cate
            };
        t.getCache("isIpx") ? e.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar"
        }) : e.setData({
            isIpx: !1,
            iphonexnavbar: ""
        }), e.setData({
            options: a
        }), a.id && (i.id = a.id, i.page = a.page, e.setData({
            id: a.id
        })), e.getlist(i)
    },
    swiperchange: function(t) {
        this.setData({
            current: t.detail.current
        })
    },
    getlist: function(i) {
        var r = this;
        e.get("membercard.detail", i, function(t) {
            if (0 == t.error) {
                if (i.id) for (var a in t.list) i.id == t.list[a].id && r.setData({
                    current: a
                });
                r.setData({
                    list: t.list
                })
            }
        })
    },
    submit: function(t) {
        var i = t.currentTarget.dataset,
            r = this;
        console.error(i), -1 != i.startbuy && ("0" != i.stock ? e.post("membercard.order.create_order", {
            id: i.id
        }, function(t) {
            0 == t.error ? wx.navigateTo({
                url: "/pages/member/membercard/pay/index?order_id=" + t.order.order_id
            }) : a.toast(r, t.message)
        }) : a.toast(r, "库存不足"))
    },
    coupon: function(t) {
        var i = this,
            r = t.currentTarget.dataset,
            o = i.data.current,
            s = i.data.list,
            n = i.data.options,
            d = {
                cate: n.cate
            }, c = {
                id: r.id,
                couponid: r.couponid
            };
        r.issend || (n.id && (d.id = n.id), e.post("membercard.get_month_coupon", c, function(t) {
            if (0 == t.error) for (var e in a.toast(i, "领取成功"), s[o].month_coupon) r.couponid == s[o].month_coupon[e].id && (s[o].month_coupon[e].isget_month_coupon = !0, i.setData({
                list: s
            }));
            else a.toast(i, t.message)
        }))
    },
    credit: function(t) {
        var i = this,
            r = t.currentTarget.dataset,
            o = i.data.list,
            s = i.data.current,
            n = (i.data.options.cate, {
                id: r.id
            });
        r.iscredit || e.post("membercard.get_month_point", n, function(t) {
            0 == t.error ? (a.toast(i, "领取成功"), o[s].isget_month_point = 1, i.setData({
                list: o
            })) : a.toast(i, t.message)
        })
    }
});